"""
Author        yongfa
Date          2022-07-14 13:43:30
LastEditTime  2023-07-08 10:48:12
LastEditors   yongfa
Description   数据结构
"""


from flask_restx import Model, fields
from app.extensions.utils.schemas import CommonSchema, PageBaseSchema


# api

ApiBaseSchema = Model("ApiBaseSchema", {
    "id": fields.Integer(description="The api ID"),
    "name": fields.String(required=True, description="The api name"),
    "label": fields.String(required=True, description="The api label"),
    "path": fields.String(required=True, description="The api path"),
    "method": fields.String(required=True, description="The api method"),
    "endpoint": fields.String(required=True, description="The api endpoint"),
    "parent_id": fields.Integer(required=True, description="The api parent_id")
})

ApiSchema = CommonSchema.inherit("ApiSchema", {
    "result": fields.Nested(ApiBaseSchema, description="The user data")
})

ApiListBaseSchema = PageBaseSchema.inherit("ApiListBaseSchema", {
    "items": fields.List(fields.Nested(ApiBaseSchema), required=True, description="The data list"),
})

# 分页列表
ApiListSchema = CommonSchema.inherit('ApiListSchema', {
    "result": fields.Nested(ApiListBaseSchema, description="结果")
})

# 树形结构
ApiTreeSchema = CommonSchema.inherit('ApiTreeSchema', {
    "result": fields.List(fields.Nested(ApiBaseSchema), required=True, description="结果")
})

# menu
MenuBaseSchema = Model("MenuBaseSchema", {
    "id": fields.Integer(description="The menu ID"),
    "name": fields.String(required=True, description="The menu name"),
    "label": fields.String(required=True, description="The menu label"),
    "path": fields.String(required=True, description="The menu path"),
    "icon": fields.String(required=True, description="The menu icon"),
    "parent_id": fields.Integer(required=True, description="The menu parent_id"),
    "sort": fields.Integer(required=True, description="The menu sort"),
    "component": fields.String(required=True, description="The menu component"),
    "hidden": fields.Boolean(required=True, description="The menu hidden"),
    "meta": fields.String(required=True, description="The menu meta JSON"),
})

MenuSchema = CommonSchema.inherit("MenuSchema", {
    "result": fields.Nested(MenuBaseSchema, description="The user data")
})

MenuListBaseSchema = PageBaseSchema.inherit("MenuListBaseSchema", {
    "items": fields.List(fields.Nested(MenuBaseSchema), required=True, description="The data list"),
})

# 分页列表
MenuListSchema = CommonSchema.inherit('MenuListSchema', {
    "result": fields.Nested(MenuListBaseSchema, description="结果")
})

# 树形结构
MenuTreeSchema = CommonSchema.inherit('MenuTreeSchema', {
    "result": fields.List(fields.Nested(MenuBaseSchema), required=True, description="The data list")
})


# role
RoleBaseSchema = Model(
    "RoleBaseSchema",
    {
        "id": fields.Integer(description="The role ID"),
        "name": fields.String(required=True, description="The role name"),
        "label": fields.String(required=True, description="The role label"),
        "parent_id": fields.Integer(required=True, description="The role parent ID"),

    }
)

RoleSchema = CommonSchema.inherit("RoleSchema", {
    "result": fields.Nested(RoleBaseSchema, description="The user data")
})


RoleListBaseSchema = PageBaseSchema.inherit("RoleListBaseSchema", {
    "items": fields.List(fields.Nested(RoleBaseSchema), required=True, description="The data list"),
})

# 分页列表
RoleListSchema = CommonSchema.inherit('RoleListSchema', {
    "result": fields.Nested(RoleListBaseSchema, description="结果")
})

# 树形结构
RoleTreeSchema = CommonSchema.inherit('RoleTreeSchema', {
    "result": fields.List(fields.Nested(RoleBaseSchema), required=True, description="结果")
})

permission_schemas = {
    "ApiBaseSchema": ApiBaseSchema,
    "ApiSchema": ApiSchema,
    "ApiListBaseSchema": ApiListBaseSchema,
    "ApiListSchema": ApiListSchema,
    "ApiTreeSchema": ApiTreeSchema,
    "MenuBaseSchema": MenuBaseSchema,
    "MenuSchema": MenuSchema,
    "MenuListBaseSchema": MenuListBaseSchema,
    "MenuListSchema": MenuListSchema,
    "MenuTreeSchema": MenuTreeSchema,
    "RoleBaseSchema": RoleBaseSchema,
    "RoleSchema": RoleSchema,
    "RoleListBaseSchema": RoleListBaseSchema,
    "RoleListSchema": RoleListSchema,
    "RoleTreeSchema": RoleTreeSchema,
}
